<template>
  <el-header>
    <div class="left">
      <el-icon size="32px"  @click="handleCollapsed"><Menu /></el-icon>
      <span>企业网站门户管理系统</span>
    </div>
    <div class="right">
      <span>欢迎 {{ store.state.userInfo.username }} 回家!</span>
      <el-dropdown>
        <span class="el-dropdown-link">
          <el-icon size="26px"><User /></el-icon>
        </span>
        <template #dropdown>
          <el-dropdown-menu>
            <el-dropdown-item @click="handleCenter">个人中心</el-dropdown-item>
            <el-dropdown-item @click="handleLoginOut">退出</el-dropdown-item>
          </el-dropdown-menu>
        </template>
      </el-dropdown>
    </div>
  </el-header>
</template>

<script setup>
import { useStore } from "vuex";
const store = useStore();
import { Menu ,User} from "@element-plus/icons-vue";
import { useRouter } from "vue-router";
const router = useRouter()


const handleCollapsed = () => {
  store.commit("changeCollapsed");
};

// 跳转个人中心
const handleCenter =()=>{
  router.push('/center')
}

// 退出
const handleLoginOut =()=>{
  localStorage.removeItem("token")
  store.commit("clearUserInfo")
  router.push('/login')
}
</script>

<style scoped lang="scss">
.el-header{
  padding:0 22px;
  background-color: #2d3a4b;
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  height: 60px;
  color: white;
  .left, .right{
    display: flex;
  }
  .left{
    i{
      margin: auto 5px;
      cursor: pointer;
    }
    span{
      font-size:20px;
    }
   
  }
  .right{
    .el-dropdown{
      margin: auto 10px;
    }
  }
}
</style>
